package cn.spark.study.streaming

import org.apache.spark.SparkConf
import org.apache.spark.streaming.StreamingContext
import org.apache.spark.streaming.Seconds

object WordCount {
  def main(args: Array[String]): Unit = {
       val conf = new SparkConf()
           .setMaster("local[2]")
           .setAppName("WordCount")
       
       val ssc = new StreamingContext(conf,Seconds(3))
       val lines = ssc.socketTextStream("spark1", 9999)
       val pairDS = lines.flatMap { _.split(" ") }.map { (_,1) }.reduceByKey(_ + _)
       
       pairDS.print()
       
       ssc.start()
       ssc.awaitTermination()
       
  }
}